import axios from "../utils/http";

//获取所有的任务
export function reqGetAllTodos(){
  return axios.get('/todos');
}

//新增一个任务
// todo 任务对象
// createNewTodo({title: 'router', done: false})
export function reqCreateNewTodo(todo){
  return axios.post('/todos', todo);
}

//修改某个任务的状态
export function reqUpdateTodo(id, done){
  //                                
  return axios.patch(`/todos/${id}`, {done: done});
}

//删除某个任务
export function reqRemoveTodo(id){
  return axios.delete(`/todos/${id}`);
}

//批量任务状态
export function reqCheckAllTodos(todos, done){
  //批量修改
  let promises = todos.map(item => {
    //发送请求
    return axios.patch(`/todos/${item.id}`, {done});
  });
  return Promise.all(promises);
}